package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysUser;
import com.hl.sfzy.entity.SysWelfareCenter;
import com.hl.sfzy.service.SysWelfareCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class SysWelfareCenterController {
    @Autowired
    private SysWelfareCenterService sysWelfareCenterService;
    /*
     * 新增
     * */
    @PostMapping("/sysWelfareCenter")
    public Result add(@RequestBody SysWelfareCenter sysWelfareCenter){
        int num = sysWelfareCenterService.add(sysWelfareCenter);
        return num > 0 ? Result.success() : Result.error();
    }

    /*
     * 删除
     * */
    @DeleteMapping("/sysWelfareCenter/{id}")
    public Result remove(@PathVariable("id") Integer id){
        int num = sysWelfareCenterService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/sysWelfareCenter")
    public Result removeBatch(Integer[] ids){
        int num = sysWelfareCenterService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();

    }

    @PutMapping("/sysWelfareCenter")
    public Result edit(@RequestBody SysWelfareCenter sysWelfareCenter){
        int num = sysWelfareCenterService.edit(sysWelfareCenter);
        return num > 0 ? Result.success() : Result.error();
    }

    @GetMapping("/sysWelfareCenter/{id}")
    public Result findById(@PathVariable("id") Integer id){
        SysWelfareCenter sysWelfareCenter = sysWelfareCenterService.findById(id);
        return Result.success(sysWelfareCenter);
    }

    @GetMapping("/sysWelfareCenter")
    public Result findAll(SysWelfareCenter sysWelfareCenter){
        List<SysWelfareCenter> list = sysWelfareCenterService.find(sysWelfareCenter);
        return Result.success(list);
    }
    @GetMapping("/sysWelfareCenter/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysWelfareCenter sysWelfareCenter) {
        Map<String, Object> map = sysWelfareCenterService.findPage(pageNum, pageSize, sysWelfareCenter);
        return Result.success(map);
    }

}
